//    Copyright (C) Kherty.  All rights reserved.
using System.Diagnostics;
using System.Windows.Media;
using OpenLS.Core.Serialization;
using OpenLS.Drawing;

namespace OpenLS.Spreadsheet
{
    ///<summary>
    /// Spreadsheet color defined by an index in a color table
    ///</summary>
    public sealed class IndexedColor : SpreadsheetColor
    {
        public IndexedColor(Color color, int index)
        {
            this._color = color;
            _indexed = index;
            if (_indexed > 1000)
                Debug.WriteLine("large color index");
            //\\this.StyleSheet = styleSheet;
        }

        readonly Color _color;
        readonly int _indexed;
        /// <summary>
        /// Get the index of the color.
        /// </summary>
        public int Index { get { return _indexed; } }

        public override int GetHashCode()
        {
            return _indexed;
        }

        public override bool Equals(object obj)
        {
            IndexedColor other = obj as IndexedColor;
            if (other == null)
                return false;
            return other._indexed == _indexed;
        }

        public override Color GetColor(ColorScheme colorScheme)
        {
            {
                return _color;
            }
        }

        internal override void WriteXmlAs(string p, WriteContext context)
        {
            using (WriteContext c = context.Write(p))
            {
                c.SetInteger("indexed", _indexed);
            }
        }
    }
}
